﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Text.RegularExpressions;

namespace FYPHP
{
    public partial class ViewProfile : System.Web.UI.Page
    {

        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["fyphp"].ConnectionString);


        protected void Page_Load(object sender, EventArgs e)
        {

            try
            {
                SqlCommand cmdUser;
                SqlDataReader dtrUser;
                conn.Open();


                String username = Session["Username"].ToString();    

                cmdUser = new SqlCommand("Select * From Users where u_id=@UID ", conn);
                cmdUser.Parameters.AddWithValue("@UID", Convert.ToInt32(Session["ID"].ToString()));

                dtrUser = cmdUser.ExecuteReader();
                dtrUser.Read();

                String userName = dtrUser["username"].ToString();
                String gender = dtrUser["u_gender"].ToString();
                String age = dtrUser["u_age"].ToString();
                
              

                string addressBeforeSplit = dtrUser["u_address"].ToString();
              
                string[] lines = addressBeforeSplit.Split('|');
              
                string address = "";

                foreach (string line in lines)
                {
                    address += " "+line;
                }

                
                String email = dtrUser["u_email"].ToString();
                String phoneNo = dtrUser["u_phone"].ToString();
                String rewardpoint = dtrUser["u_points"].ToString();
                String IC = dtrUser["u_ic"].ToString();
                
                lblName.Text = userName;
                lblIC.Text = IC;
                lblGender.Text = gender;
                lblAge.Text = age;
                lblAddress.Text = address;
                lblEmail.Text = email;
                lblPhoneNo.Text = phoneNo;
                lblRewardPoints.Text = rewardpoint;

                conn.Close();
            }
            catch (SqlException ex)
            {

            }
        }

        protected void EditProfile_Click(object sender, EventArgs e)
        {
            Session["Username"] = lblName.Text;
            Response.Redirect("EditMemberProfile.aspx");

        }

        protected void btnChangePassword_Click(object sender, EventArgs e)
        {
            Response.Redirect("MemberChangePassword.aspx");
        }

 
    }
}